/* @(#)CommitmentNodeDaoSqLite.java
** 
** Copyright (C) 2012 by Steven D. Stamps
**
**             Trademarks & Copyrights
** Flywheel Management Science(TM), Flywheel Management Model(TM),
** Flywheel Story Editor(TM) and FlywheelMS(TM) are exclusive trademarks
** of Steven D. Stamps and may only be used freely for the purpose of
** identifying the unforked version of this software.  Subsequent forks
** may not use these trademarks.  All other rights are reserved.
**
** DecKanGL (Decorated Kanban Glyph Language) and TribKn (Tribal Knowledge)
** are also exclusive trademarks of Steven D. Stamps.  These may be used
** freely within the unforked FlywheelMS application and documentation.
** All other rights are reserved.
**
** gConGUI (game Controller Graphical User Interface) is an exclusive
** trademark of Steven D. Stamps.  This trademark may be used freely
** within the unforked FlywheelMS application and documentation.
** All other rights are reserved.
**
** Trademark information is available at
** <http://www.flywheelms.com/trademarks>
**
** Flywheel Management Science(TM) is a copyrighted body of management
** metaphors, governance processes, and leadership techniques that is
** owned by Steven D. Stamps.  These copyrighted materials may be freely
** used, without alteration, by the community (users and developers)
** surrounding this GPL3-licensed software.  Additional copyright
** information is available at <http://www.flywheelms.org/copyrights>
**
**              GPL3 Software License
** This program is free software: you can use it, redistribute it and/or
** modify it under the terms of the GNU General Public License, version 3,
** as published by the Free Software Foundation. This program is distributed
** in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
** even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
** PURPOSE.  See the GNU General Public License for more details. You should
** have received a copy of the GNU General Public License, in a file named
** COPYING, along with this program.  If you cannot find your copy, see
** <http://www.gnu.org/licenses/gpl-3.0.html>.
*/

package com.flywheelms.library.fmm.database.sqlite.dao;

import java.util.HashMap;

import android.content.ContentValues;
import android.database.Cursor;

import com.flywheelms.library.fmm.database.column.CommitmentNodeColumnDefinition;
import com.flywheelms.library.fmm.helper.FmmDateHelper;
import com.flywheelms.library.fmm.node.interfaces.horizontal.FmmNodeCommitment;

public abstract class CommitmentNodeDaoSqLite<T extends FmmNodeCommitment> extends FmmNodeDaoSqLite<T>
		implements CommitmentNodeColumnDefinition {

	@Override
	protected void buildColumnIndexMap(Cursor aCursor) {
		putColumnIndexMapEntry(this.columnIndexMap, aCursor, column_SEQUENCE);
		putColumnIndexMapEntry(this.columnIndexMap, aCursor, column_COMPLETION_COMMITMENT_TYPE_CODE);
		putColumnIndexMapEntry(this.columnIndexMap, aCursor, column_SUGGESTED_BY);
		putColumnIndexMapEntry(this.columnIndexMap, aCursor, column_SUGGESTED_TIMESTAMP);
		putColumnIndexMapEntry(this.columnIndexMap, aCursor, column_PROPOSED_BY);
		putColumnIndexMapEntry(this.columnIndexMap, aCursor, column_PROPOSED_TIMESTAMP);
		putColumnIndexMapEntry(this.columnIndexMap, aCursor, column_CONFIRMED_BY);
		putColumnIndexMapEntry(this.columnIndexMap, aCursor, column_CONFIRMED_TIMESTAMP);
		putColumnIndexMapEntry(this.columnIndexMap, aCursor, column_DECLINED_BY);
		putColumnIndexMapEntry(this.columnIndexMap, aCursor, column_DECLINED_TIMESTAMP);
		putColumnIndexMapEntry(this.columnIndexMap, aCursor, column_CANCELED_BY);
		putColumnIndexMapEntry(this.columnIndexMap, aCursor, column_CANCELED_TIMESTAMP);
	}
	
	@Override
	protected void getColumnValues(HashMap<String, Integer> aHashMap, Cursor aCursor, T aCommitmentNode) {
		aCommitmentNode.setSequence(aCursor.getInt(aHashMap.get(column_SEQUENCE)));
		aCommitmentNode.setCompletionCommitmentType(aCursor.getString(aHashMap.get(column_COMPLETION_COMMITMENT_TYPE_CODE)));
		aCommitmentNode.setSuggestedBy(aCursor.getString(aHashMap.get(column_SUGGESTED_BY)));
		aCommitmentNode.setSuggestedTimestamp(FmmDateHelper.getDateFromIso8601DateString(aCursor.getString(aHashMap.get(column_SUGGESTED_TIMESTAMP))));
		aCommitmentNode.setProposedBy(aCursor.getString(aHashMap.get(column_PROPOSED_BY)));
		aCommitmentNode.setProposedTimestamp(FmmDateHelper.getDateFromIso8601DateString(aCursor.getString(aHashMap.get(column_PROPOSED_TIMESTAMP))));
		aCommitmentNode.setConfirmedBy(aCursor.getString(aHashMap.get(column_CONFIRMED_BY)));
		aCommitmentNode.setConfirmedTimestamp(FmmDateHelper.getDateFromIso8601DateString(aCursor.getString(aHashMap.get(column_CONFIRMED_TIMESTAMP))));
		aCommitmentNode.setDeclinedBy(aCursor.getString(aHashMap.get(column_DECLINED_BY)));
		aCommitmentNode.setDeclinedTimestamp(FmmDateHelper.getDateFromIso8601DateString(aCursor.getString(aHashMap.get(column_DECLINED_TIMESTAMP))));
		aCommitmentNode.setCanceledBy(aCursor.getString(aHashMap.get(column_CANCELED_BY)));
		aCommitmentNode.setCanceledTimestamp(FmmDateHelper.getDateFromIso8601DateString(aCursor.getString(aHashMap.get(column_CANCELED_TIMESTAMP))));
	}

	@Override
	public ContentValues buildContentValues(
			T anObject) {
		ContentValues theContentValues = new ContentValues();
		theContentValues.put(column_SEQUENCE, anObject.getSequence());
		theContentValues.put(column_COMPLETION_COMMITMENT_TYPE_CODE, anObject.getCompletionCommitmentTypeCode());
		theContentValues.put(column_PROPOSED_BY, anObject.getProposedByNodeIdString());
		theContentValues.put(column_PROPOSED_TIMESTAMP, FmmDateHelper.getIso8601DateString(anObject.getProposedDate()));
		theContentValues.put(column_CONFIRMED_BY, anObject.getConfirmedByNodeIdString());
		theContentValues.put(column_CONFIRMED_TIMESTAMP, FmmDateHelper.getIso8601DateString(anObject.getConfirmedDate()));
		theContentValues.put(column_DECLINED_BY, anObject.getDeclinedByNodeIdString());
		theContentValues.put(column_DECLINED_TIMESTAMP, FmmDateHelper.getIso8601DateString(anObject.getDeclinedDate()));
		theContentValues.put(column_CANCELED_BY, anObject.getCanceledByNodeIdString());
		theContentValues.put(column_CANCELED_TIMESTAMP, FmmDateHelper.getIso8601DateString(anObject.getCanceledDate()));
		return theContentValues;
	}

}
